/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 线程工厂类Main
 * @Description *
 * @Package concurrent.mthread.daemon
 * @Since 2021/7/27 1:50 下午
 */
package concurrent.mthread.daemon;

import concurrent.mthread.daemon.factory.DaemonThreadFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class DaemonFromFactory implements Runnable {


    @Override
    public void run() {
        while (true) {
            try {
                TimeUnit.MILLISECONDS.sleep(100);
                System.out.println(Thread.currentThread() + " " + this);

            } catch (InterruptedException e) {
                System.out.println("Interrupted!");
            }

        }
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService exec = Executors.newCachedThreadPool(new DaemonThreadFactory(1));

        for (int i = 0; i < 10; i++)
            exec.execute(new DaemonFromFactory());

        System.out.println("All daemons started!");
        TimeUnit.MILLISECONDS.sleep(5000);
    }
}
